<?php

namespace App\Http\Controllers\Drivers\V2;

use App\Http\Controllers\Controller;
use App\Http\Requests\UsersRequests;
use App\Services\DriverLoginService;
use Illuminate\Http\Request;

/**
 * Class LoginController
 * @package App\Http\Controllers\Drivers\V2
 * 司机端App登录
 */
class LoginController extends Controller
{
    /**
     * @param Request $request
     * @return LoginController|\Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BobException
     * 登录/注册
     *
     */
    public function login(Request $request, DriverLoginService $driverLoginService, UsersRequests $userValidate)
    {
        $request_data = $request->post();
        $request_data['type'] = $request->post('type', 2); //默认密码登录   1 验证码登录  2 密码登录 默认密码登录
        $is_summary = $request_data['type'] == 2 ? 'login' : 'code_login';
        if (!$userValidate->scene($is_summary)->check($request_data)) return $this->sendError($userValidate->getError());
        $res = $driverLoginService->login($request_data);
        return $this->sendJson($res);
    }
}
